package com.example.team.service.Imp;

import com.example.team.dao.IOrderDao;
import com.example.team.entity.Order;
import com.example.team.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 编写者：蓝江富
 * 2023年10月30日21:33:03
 */
//服务接口规范的方法实现
@Service
public class IOrderServiceImpl implements IOrderService {

    @Autowired
    private IOrderDao orderMapper;
    @Override
    public int insertOrder(Order order) {
        //设置成功状态
        int orderValue;
        Order order1=new Order();
        order1.setOrderId(order.getOrderId());
        Order allOrder=orderMapper.getOrderById(order1);
        if(allOrder!=null){
            orderValue = -1;
        }else {
            orderValue= orderMapper.insertOrder(order);
        }
        //返回状态码
        return orderValue;
    }

    @Override
    public int deleteOrder(Order order) {
        //设置成功状态
        int orderValue;
        Order order1=new Order();
        order1.setOrderId(order.getOrderId());
        Order allOrder=orderMapper.getOrderById(order1);
        if(allOrder==null){
            orderValue = -1;
        }else {
            orderValue= orderMapper.deleteOrder(order);
        }
        //返回状态码
        return orderValue;
    }

    @Override
    public int updateOrder(Order order) {
        //设置成功状态
        int orderValue;
        //通过主键id对数据更新，判断是否存在目标id
        Order order1=new Order();
        order1.setOrderId(order.getOrderId());
        Order allOrder=orderMapper.getOrderById(order1);
        if(allOrder==null){
            //如果为空，说明无法找到匹配的目标Id，设置状态码-1
            orderValue = -1;
        }else {
            //否则执行更新数据库功能，同时赋值更新成功的数据数量到状态码
            orderValue= orderMapper.updateOrder(order);
        }
        //返回状态码
        return orderValue;
    }

    @Override
    public List<Order> getAllOrder(Order order) {
        return orderMapper.getAllOrder(order);
    }

    @Override
    public Order getOrder(Order order) {
        return orderMapper.getOrder(order);
    }
}
